package report2.classes;

import java.util.Objects;

/**
 * Author：zouran
 * Date：2023/4/20  14:48
 * Description:数据结构
 */
public class MyProcess {
    //进程名字
    private String name;
    //到达时间
    private Integer arrival;
    //所需服务时间
    private Integer service;
    //权值，1为优先级最高
    private Integer weight;
    //进程开始作业时间
    private Integer start;
    //进程结束作业时间
    private Integer end;
    //当前进程以完成的作业时间
    private Integer current;

    //无参构造初始化进程
    public MyProcess() {
        this.current = 0;
        //时间片轮转使用
        this.end = 0;
    }

    //格式化输出
    public void print() {
        System.out.printf("\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", name, arrival, service, start, end, getPeriod1(), getPeriod2());
    }

    //判断是否进程完成，service==current时代表完成
    public boolean isFinish() {
        return Objects.equals(service, current);
    }

    //计算周转周期
    public double getPeriod1() {
        return (this.end - this.arrival);
    }

    //计算带权周转周期
    public double getPeriod2() {
        return (double) (this.end - this.arrival) / this.service;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getArrival() {
        return arrival;
    }

    public void setArrival(Integer arrival) {
        this.arrival = arrival;
    }

    public Integer getService() {
        return service;
    }

    public void setService(Integer service) {
        this.service = service;
    }

    public Integer getWeight() {
        return weight;
    }

    public void setWeight(Integer weight) {
        this.weight = weight;
    }

    public Integer getStart() {
        return start;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    public Integer getEnd() {
        return end;
    }

    public void setEnd(Integer end) {
        this.end = end;
    }

    public Integer getCurrent() {
        return current;
    }

    public void setCurrent(Integer current) {
        this.current = current;
    }
}
